package com.xbongbong.saas.enums.business;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import lombok.Getter;

/**
 * 红冲回款单枚举
 *
 * @author feng.zheng
 * @version v1.0
 * @date 2019/3/14 15:37
 * @since v1.0
 */
@Getter
public enum RedPaymentSheetEnum {
    //
    PAYMENT_NO(PaymentSheetEnum.PAYMENT_SHEET_NO.getAttr(), "enum.redPaymentSheet.attrName.payment_no", "paymentNo", FieldTypeEnum.TEXT.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9990, 1, 1),
    BELONG_ID(PaymentSheetEnum.BELONG_ID.getAttr(), "enum.redPaymentSheet.attrName.belong_id", "belongId", FieldTypeEnum.USER.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9980, 1, 1),
    CUSTOMER(PaymentSheetEnum.CUSTOMER_ID.getAttr(), "enum.redPaymentSheet.attrName.customer", "customer", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 0, 1, ShowTypeEnum.ALL.getCode(), 9970, 1, 1),
    CONTRACT(PaymentSheetEnum.CONTRACT.getAttr(), "enum.redPaymentSheet.attrName.contract", "contract", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9960, 1, 1),
    PAYMENT(PaymentSheetEnum.PAYMENT.getAttr(), "enum.redPaymentSheet.attrName.payment", "payment", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9955, 1, 1),
    PAYMENT_TIME(PaymentSheetEnum.PAYMENT_TIME.getAttr(), "enum.redPaymentSheet.attrName.payment_time", "paymentTime", FieldTypeEnum.DATETIME.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9950, 1, 1),
    PAY_METHOD(PaymentSheetEnum.PAY_METHOD.getAttr(), "enum.redPaymentSheet.attrName.pay_method", "payMethod", FieldTypeEnum.COMBO.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9940, 1, 0),
    MEMO(PaymentSheetEnum.MEMO.getAttr(), "enum.redPaymentSheet.attrName.memo", "memo", FieldTypeEnum.TEXTAREA.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0),
    LINK_SHEET("text_8", "enum.redPaymentSheet.attrName.link_sheet", "linkSheet", FieldTypeEnum.LINK_BUSINESS_MULTI.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9910, 1, 0),
    RED_AMOUNT("num_6", "enum.redPaymentSheet.attrName.red_amount", "redAmount", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9900, 1, 0 ),
    LINK_SHEET_LINKED_TEXT("text_9", "enum.redPaymentSheet.attrName.link_sheet_linked_text", "linkSheetLinkedText", FieldTypeEnum.TEXT.getType(), 3, 0, 0, ShowTypeEnum.NONE.getCode(), 9890, 1, 0),;
    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 详见
     *
     * @see ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;

    RedPaymentSheetEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                        Integer editHide, Integer showType, Integer sort, Integer visible, Integer required) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
    }

    /**
     * 对data内的字段拼上“data.”
     *
     * @param cache
     * @return java.lang.String
     * @author zcp
     * @date 2019/3/1 18:12
     * @version v1.0
     * @since v1.0
     */
    public static String getAttrConnectData(RedPaymentSheetEnum cache) {
        return "data." + cache.getAttr();
    }

    /**
     * 获取es查询、聚合字段
     * data在库内是json对象，对data字段内某个key做es【精确查询】时，需要在其前拼上“data.”，且【text等类型的】要在后面拼“.keyword”
     *
     * @param cache 当前枚举对象
     * @return java.lang.String 处理后的聚合字段
     * @author zcp
     * @date 2019/2/21 14:59
     * @version v1.0
     * @since v1.0
     */
    public static String getEsAttr4Keyword(RedPaymentSheetEnum cache) {
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(cache.fieldType);
        //字段类型为text，或者字段在es内的类型时text，则需要在后面拼上“.keyword”
        boolean flag = fieldTypeEnum == FieldTypeEnum.TEXT || "text".equals(fieldTypeEnum.getEsalias());
        if (flag) {
            return "data." + cache.getAttr() + ".keyword";
        }
        return "data." + cache.getAttr();
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public static String getI18nValue(String value) {
        return I18nMessageUtil.getMessage(value);
    }
}
